<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!--#include file="inc/ImportMethod.php"-->
<?php 
require "DataLoad.php";
CheckAdmin2();
?>

<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>

</head>

<body>
<div class="header">
<?php require "menu.php"; ?>
</div>
<div class="main">

<?php 
switch (${"Action"}) {
	case "Import":
sqlInitializeData($_POST["FormatData"],$_POST["class_name"]);
		print "<div class='message'>导入成功,你可以: <a href='admin_MerDKPImport.php' class='abtn3'>继续导入</a> <a href='admin_SpecEvent.php' class='abtn'>查看导入的调分事件</a></div>";
		break;
	default:

?>

<form method=post action="?Action=Import">
<table class="outframe">
<tr><th>从外部数据导入初始化分值</th></tr>
<tr><td>复制MerDKP数据或者整理好的Excel表格[<a href="http://sites.google.com/site/wowfsdkp/Home/shi-yong-jiao-cheng" target="_blank">?</a>]到这里,每次只导入其中一个DKP分类</td></tr>
<tr><td>第1步:<br><textarea name="DKPDATA" style="width:500px;height:200px;">
MerDKP示例:

MerDKP_Table[1] = { &lt;&lt; -----以这行开始
{name="成员甲",class="猎人",dkp=0.00,online=1},
{name="成员乙",class="德鲁伊",dkp=5.00,online=1},
};
MerDKP_Table[1].title="T5级";
MerDKP_Table[1].whisper="1";
MerDKP_Table[1].key="T5级"; &lt;&lt; ----- 以这行结束
</textarea></td></tr>
<tr><td>第2步:<br><a href="javascript:void(0)" name="btn1" class="abtn">来自MerDKP</a> <a href="javascript:void(0)" name="btn2" class="abtn">来自Excel</a> 选择你的数据来源</td></tr>

<tr><td><textarea name="FormatData" style="width:500px;height:200px;"></textarea></td></tr>
<tr><td>转换后的数据应该是像这样: 名字,职业,DKP,名字,职业,DKP, ... 如果不是请勿提交</td></tr>
<tr><td>第3步:<br>选择目标分类 <?php     echo formselect("raid_class","id","class_name"," ");?></td></tr>
<tr><td>注意:请勿重复提交同一成员的同一分值多次,这样会造成双倍分值, 完成后可以在调分记录中再次检查</td></tr>
<tr><td><input type="submit" value="导入"> </td></tr>
<tr><td>另外:只有当某成员在FSDKP的活动中有记录时才会在DKP表中被列出</td></tr>
</table>

</form>

<?php 
		break;
} 
?>
</div>
<?php require "footer.php"; ?>


<script language="JavaScript">
$("a[name=btn1]").click( function () {
	$("textarea[name=FormatData]").val(cMerDKP($("textarea[name=DKPDATA]").val()));
});

$("a[name=btn2]").click( function () {
	$("textarea[name=FormatData]").val(cExcel($("textarea[name=DKPDATA]").val()));
});

function cMerDKP(txt) {
	var ArrDKP = new Array();
	//清理空格换行
	var Rxtxt = txt.replace( /[\n\r\s]/g , "");
	//取得DKP分类部分
	Rxtxt = Rxtxt.match(/(MerDKP_Table\[\d\])=\{.*\1.key=\".*\";/g);
	//获得组名字
	var strGroupName = Rxtxt[0].match(/\.title=\"(.[^\"]*)\"/);
	//获得按条分数组
	Rxtxt = Rxtxt[0].match(/\{name=\"(.[^\"]*)\",class=\"(.[^\"]*)\",dkp=(.[^,]*),online=\d\},/g);
	//获得2维数组{条目数,2} 0职业 1名字 2分数
	for (i =0 ; i < Rxtxt.length ; i++ ) {
		Rxtxt[i] = Rxtxt[i].match(/\{name=\"(.[^\"]*)\",class=\"(.[^\"]*)\",dkp=(.[^,]*),online=\d\},/)
		ArrDKP[i] = [ Rxtxt[i][1] ,Rxtxt[i][2],Rxtxt[i][3]];
	}
	return ArrDKP;
};

function cExcel(txt) {
	var ArrDKP = new Array();
	var Rxtxt = txt.replace( /[\n\r\s]/g , ",");
	var Rxtxt = Rxtxt.replace( /,,/g , "");
	var Rxtxt = Rxtxt.replace( /,,/g , "");
	var Rxtxt = Rxtxt.replace( /^,/g , "");
	var Rxtxt = Rxtxt.replace( /,$/g , "");
	return Rxtxt
};

</script>

</body>
</html>
<?php 
function sqlInitializeData($data,$c) {
	extract($GLOBALS);

	$arrData=explode(",",$data);
	for ($ia=0; $ia<=count($arrData); $ia=$ia+3) {    $sql="Select * from player where Player_name='".$arrData[$ia]."'";
		$result = mysql_query($sql);$sql    $conn
		if ($result->eof || $result->bof) {

			$result->close;
			$sql="select * from player where (id is null)";
			$result = mysql_query($sql);$sql      $conn
			$result->addnew;
			$result["player_name"]=$arrData[$ia];
			$result["player_class"]=getFormatProfessionName($arrData[$ia+1]);
			$result["player_race"]="未知";
			$result["player_level"]=$DefalutPlayerLevel;
			$result["player_honor"]="";
			$result["player_jointime"]=time()();
			$result["player_guildlevel"]="";
			$result["player_DKP"]=0;
			$result["player_skill_1"]="";
			$result["player_skill_2"]="";
			$result["player_note"]="";
			$result["player_activist"]=0;
			$result["player_looted"]="";
			$result["player_raidnum"]=0;
			$result["player_state"]="正常";
			$result->update;
			print "添加成员: ".$arrData[$ia]." Done";
			$result->close;
		}
			else
		{

			print "现有成员: ".$arrData[$ia];
			$result->close;
		} 


sqlSpecEvent($arrData[$ia],$c,$arrData[$ia+2],"其它","系统初始化分值导入");

	}

	return $function_ret;
} 


function sqlSpecEvent($n,$rc,$dkp,$ec,$eo) {
	extract($GLOBALS);
//str名字, DKP分类ID, dkp, str调分类型, 解释
	$sql="select * from raid_event where (id is null)";
	$result = mysql_query($sql);$sql  $conn
	$result->addnew;
	$result["event_object"]=$n;
	$result["raid_class"]=intval($rc);
	$result["event_dkp"]=$dkp;
	$result["event_class"]=$ec;
	$result["event_object2"]=$eo;
	$result["event_time"]=time()();
	$result->update;
	print " 调分: ".$dkp." Done<br>";
	$result->close;
	return $function_ret;
} 
?>
